package com.hnkywl.sts.action.base;

import com.hnkywl.sts.entity.base.Sjzdsy;
import com.hnkywl.sts.service.base.SjzdsyService;
import com.hnkywl.sts.service.base.SjzdzService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 数据字典索引表现类
 * User: Administrator
 * Date: 13-3-25
 * Time: 下午3:33
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/base/sjzdsy")
public class SjzdsyAction extends SimpleActionSupport{
    private SjzdzService sjzdzService;
    private SjzdsyService sjzdsyService;
    //数据字典索引实体
    private Sjzdsy sjzdsy ;
    //编码
    private String bm;
    //名称
    private String mc;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //数据字典索引ID
    private Long sjzdsyId ;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;

    /**
     * 数据字典索引分页查询
     */
    @Action("sjzdsyList")
    public void sjzdsyList() {
        this.renderJson(this.sjzdsyService.findAllSjzdsy(mc,bm,page, rows));
    }
    /**
     *   获得索引下的数据字典值
     */
    @Action("get_sjzdz")
    public void getSjzdz() {
        renderJson(sjzdsyService.findSjzdsyJson(bm));
    }

    /**
     *   判断增加修改
     */
    @Action("sjzdsy_content")
    public String sjzdsyContent() {
        //进入update页面
        if (sjzdsyId != null){
            sjzdsy = sjzdsyService.findSjzdsyDetail(sjzdsyId);
        }else{
            //进入add页面
            sjzdsy = new Sjzdsy();
        }
        return SUCCESS;
    }
    /**
     * 方法名:     addSjzdsy
     * 功能描述:    添加数据字典索引
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     */
    @Action("add_sjzdsy")
    public void addSjzdsy() {
        try {
            this.sjzdsyService.saveSjzdsy(sjzdsy);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加数据字典成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 方法名:     deleteSjzdsy
     * 功能描述:   删除数据字典索引
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     */
    @Action("delete_sjzdsy")
    public void deleteSjzdsy() {
        try {
            this.sjzdsyService.deleteSjzdsy(sjzdsyId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除数据字典成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 方法名:     updateSjzdsy
     * 功能描述:     更改数据字典索引
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     */
    @Action("update_sjzdsy")
    public void updateSjzdsy() {
        try {
            this.sjzdsyService.updateSjzdsy(sjzdsy);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改数据字典成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!sjzdsyService.ajaxValidate(sjzdsyId, validateVal, validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }
  //=============getter===setter==============
    public String getBm() {
        return bm;
    }

    public void setBm(String bm) {
        this.bm = bm;
    }

    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Sjzdsy getSjzdsy() {
        return sjzdsy;
    }

    public void setSjzdsy(Sjzdsy sjzdsy) {
        this.sjzdsy = sjzdsy;
    }

    public Long getSjzdsyId() {
        return sjzdsyId;
    }

    public void setSjzdsyId(Long sjzdsyId) {
        this.sjzdsyId = sjzdsyId;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public SjzdzService getSjzdzService() {
        return sjzdzService;
    }

    public void setSjzdzService(SjzdzService sjzdzService) {
        this.sjzdzService = sjzdzService;
    }

    @Autowired
    public void setSjzdsyService(SjzdsyService sjzdsyService) {
        this.sjzdsyService = sjzdsyService;
    }
}
